local ciwei = fk.CreateSkill{
    name = "jin_heg__ciwei",
}

Fk:loadTranslationTable{
    ["jin_heg__ciwei"] = "慈威",
    [":jin_heg__ciwei"] = "其他角色于你的回合内使用牌时，若场上有本回合使用或打出过牌且不与其势力相同的其他角色，你可弃置一张牌令此牌无效。",
    ["#jin_heg__ciwei-discard"] = "慈威: 你可以弃置一张牌令此牌无效",

    ["$jin_heg__ciwei1"] = "乃家乃邦，是则是效。",
    ["$jin_heg__ciwei2"] = "其慈有威，不舒不暴。",
}

local H = require "packages.ol_hegemony.util"

ciwei:addEffect(fk.CardUsing,{
    anim_type = "control",
    can_trigger = function(self, event, target, player, data)
    if target ~= player and player:hasSkill(ciwei.name) and player.room.current == player and not player:isNude() then
      if #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data
        return use.from ~= player and not use.from.dead and H.compareKingdomWith(use.from, target, true)
      end, Player.HistoryTurn) > 0 then
        return true
      end
      if #player.room.logic:getEventsOfScope(GameEvent.RespondCard, 1, function(e)
        local use = e.data
        return use.from ~= player and not use.from.dead and H.compareKingdomWith(use.from, target, true)
      end, Player.HistoryTurn) > 0 then
        return true
      end
    end
  end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local discard = room:askToDiscard(player,{
            min_num = 1,
            max_num = 1,
            include_equip = true,
            skill_name = ciwei.name,
            cancelable = true,
            prompt = "#jin_heg__ciwei-discard",
            skip = true,
        })
        if #discard > 0 then
          event:setCostData(self, {discard = discard})
          return true
        end
     end,
     on_use = function(self, event, target, player, data)
        local room = player.room
        room:throwCard(event:getCostData(self).discard, ciwei.name, player, player)
        data.toCard = nil
        data:removeAllTargets()
     end,
})

return ciwei